//
//  RotateTransitionDelegate.m
//  仿酷我音乐
//
//  Created by mac on 15/11/19.
//  Copyright © 2015年 mac. All rights reserved.
//

#import "RotateTransitionDelegate.h"

@implementation RotateTransitionDelegate

///(代理方法)提供modal转场动画的对象------->我们这个返回值对象必须要遵守一个转场动画的协议
-(id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source{
    ///Users/mac/Desktop/资料/练习（新浪微博）/my_KuWoMusic/仿酷我音乐/仿酷我音乐/RotateTransitionDelegate.m:16:12: Returning 'RotateTransitionDelegate *const __strong' from a function with incompatible result type 'id<UIViewControllerAnimatedTransitioning> _Nullable'
    return self;
}
//因为我们遵守了协议，在协议里有两个必须要实现的方法，，一个可选的方法，所以我们必须要实现
///b必选的，专场动画的详细信息
-(void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext{
    
    //容器视图
    UIView *containerView = [transitionContext containerView];
    
    //目标视图
    UIView *toView = [transitionContext viewForKey:UITransitionContextToViewKey];
    
    //将目标控制器添加到容器里
    [containerView addSubview:toView];
    
    //设置初始形变
    toView.transform = CGAffineTransformMakeRotation(-M_PI_2);
   
    //动画效果
    [UIView animateWithDuration:[self transitionDuration:transitionContext] delay:0.0 usingSpringWithDamping:0.8 initialSpringVelocity:10 options:0 animations:^{
        
        //回复视图形变
        toView.transform = CGAffineTransformIdentity;

    } completion:^(BOOL finished) {
        
    // 转场动画的末尾必须调用的方法，告诉视图控制器转场动画已经结束，否则系统会一直等待转场动画进行！
    [transitionContext completeTransition:YES];
    }];
    
    
}
///b必选的，专场动画时长
-(NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext{
    return 0.25;
}


@end
